<?php
namespace app\admin\controller\mall;


use app\common\controller\AdminController;
use think\App;
use think\facade\Db;

class Articles extends AdminController
{
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = app('app\common\model\media\Articles');
    }

    public function get_with(){
        return 'Store';
    }

    public function get_where($arr = []){
        $array[]=['type','=',2];
        if(isset($arr['title']) && !empty($arr['title'])){
            $array[] = ['title','like','%'.$arr['title'].'%'];
        }
        return $array;
    }

    public function action(){

        $param= $this->request->param();

        try{
            $row = $this->model->where('id',$param['id'])->find();
            if(isset($param['is_top'])){
                if($param['is_top']==1){
                    $param['top_time'] = time();
                }else{
                    $param['top_time'] = null;
                }


            }

            $row->save($param);

        }catch (\Exception $exception){
            return json(['code'=>1,'msg'=>$exception->getMessage()]);
        }
        return json(['code'=>0,'msg'=>'操作成功']);
    }
}